AddCSLuaFile("shared.lua")
AddCSLuaFile("cl_init.lua")
	
include('shared.lua')
function ENT:Initialize()
	-- don't forget collision group none
	if (not (self.Model or self.Mass or self.SITP_AsteroidHealth)) then
		self.Entity:Remove()
	end
	self:SetModel(self.Model)
	self:PhysicsInit (SOLID_VPHYSICS)
		
	self:Activate()
		
	self.SpecialHealth = false
	self.SpecialDamage = true
		
	local phys = self.Entity:GetPhysicsObject()
	if(phys:IsValid()) then
		phys:SetMass(self.Mass)
		phys:Wake()
	end
	
	self.VisModel = ents.Create("prop_physics")
	self.VisModel:SetPos(self:GetPos())
	self.VisModel:SetAngles(self:GetAngles())
	self.VisModel:SetModel(self.Model)
	self.VisModel:Spawn()
		
	self.VisModel:SetMaterial("models/props_lab/xencrystal_sheet")
		
	self.VisModel:SetSolid(SOLID_NONE)
	self.VisModel:SetParent(self)
	self.VisModel:SetColor(255, 255, 255, 180)
	
	self:SetNetworkedEntity( "vismodel", self.VisModel )
	self:SetNetworkedInt( "maxhealth", self.SITP_AsteroidHealth )
		
	self:NextThink( CurTime() + math.random() )
end
	
function ENT:ACF_OnDamage( Entity, Energy, FrAera, Angle, Inflictor )
	-- Can't blast these asteroids, sah.
	local HitRes = {}
		HitRes.Damage = 0
		HitRes.Overkill = 0
		HitRes.Loss = 1
		HitRes.Kill = false
		HitRes.Ricochet = true
	return HitRes
end
	
function ENT:Think()
	if( self.SITP_AsteroidHealth <= 0 ) then
		if(self.LastHit and self.LastHit:IsValid() and self.LastHit:IsPlayer()) then
			self.LastHit:SetFrags(self.LastHit:Frags() + self.SITP_Score)
			print("An Asteroid was just mined for " .. tostring(self.SITP_Score) .. " points!")
		end
	
		ACF_HEKill( self , Vector(math.random(-1, 1), math.random(-1, 1), math.random(-1, 1)) , math.random(0, 50) )
	end
	self:NextThink( CurTime() + 0.1 )
end

function ENT:OnRemove()
	SITP_TotalAsteroids = math.max(SITP_TotalAsteroids - 1, 0)
end